package com.dd;

import com.javapig.util.XMLProperties;

import java.util.*;
import java.io.*;
import java.text.*;

/**
 * ��ֶ���
 */
public class SysGlobals
{
  //------------start------------
  //对应数据库里lib_id表中设置
	//id变量总数，增加新ID时，也要手工修改这个值
  public static final int globalsFiledCount = 7;
  //未使用字段(保留)
  public static final int unUserd = 0;
  //采购报价表ID
  public static final int CGBJ_ID = 1;
  //采购商品表ID
  public static final int CGSP_ID = 2;
  //采购公司表ID
  public static final int CGGS_ID = 3; 
  //项目表ID
  public static final int XM_ID = 4;
  //用户表ID
  public static final int USER_ID = 5;
  //采购报价单单据唯一编号
  public static final int CGBJ_NO = 6;
  //-----------end---------------
  
  
  //-------------start--------
  //用户等级
  //系统管理员
  public static int C_Admin = 1;
  //采购员
  public static int C_CaiGouYuan = 2;
  //审核员
  public static int C_ShenHeYuan = 3;
  //--------------end------------
  
  
  //----------------start--------
  //下面是审核权限
  //得到权限通过下面的方法来得到
  //UserManager.GetShenHeYuanQuanXianByUserID()
  //审核自己管理的项目,可以创建 和查看 自己管理的项目的比价单, 
  //操作比价单的操作有, 提交,
  public static int C_ShenHe_XiangMuZu = 1;
  //操作比价单的操作有, 提交,
  public static int C_ShenHe_CaiGouBu = 2;
  
  //只有比价部才有权利去修改 审核价一列的信息
  //操作比价单的操作有, 提交,
  public static int C_ShenHe_BiJiaBu = 3;
  
  //有结束比价单的权利,结束及就是审批通过,不用再要总裁审核
  //操作比价单的操作有, 提交,结束审批
  public static int C_ShenHe_JingLi = 4;
  //有同意,和拒绝的权限.
  //操作比价单的操作有, 同意,拒绝
  public static int C_ShenHe_ZhongCai = 5;
  //-----------------end-------------------
  
  //------------start--------
  //审核状态
  //等待
  public static String SH_STATE_DD = "0";
  //通过
  public static String SH_STATE_TJ = "1";
  //拒绝
  public static String SH_STATE_JJ = "2";
  //---------end---------
  
  
  //---------start------------
  // 时间信息
  public static final int PERM_VALUE_BYID = 1;
  public static final int PERM_VALUE_BYNAME = 2;
  public static final long SECOND = 1000;
  public static final long MINUTE = 60 * SECOND;
  public static final long HOUR   = 60 * MINUTE;
  public static final long DAY    = 24 * HOUR;
  public static final long WEEK   = 7 * DAY;
  //-----------end--------
  
  
  //vodϵͳ�����ļ�
  private static final String VOD_CONFIG_FILENAME = "vod_config.xml";
        
  public static String dataBaseName = "dindanguanli"; // 数据库名

    /**
     * Location of the VodHome directory. All configuration files should be
     * located here. This value can be set explicitly by an outside class or
     * this class will attempt to load it from the <tt>jive_init.properties</tt>
     * file.
     */
    public static String vodHome = null;

    /**
     * XML properties to actually get and set the Jive properties.
     */
    private static XMLProperties properties = null;

    private static Locale locale = null;
    private static TimeZone timeZone = null;
    private static DateFormat dateFormat = null;
    private static DateFormat dateTimeFormat = null;
    
    /**
     * Returns the location of the <code>jiveHome</code> directory.
     *
     * @return the location of the jiveHome dir.
     */
    public static String getSysHome() {
        if (vodHome == null) {
            vodHome = new InitPropLoader().getVodHome();
            // If jiveHome is still null, try loading it as a system property
            if (vodHome == null) {
                vodHome = System.getProperty("vodHome");
            }
        }
        return vodHome;
    }

    /**
     * ���ص�ǰϵͳ�İ汾��
     * @return String
     */
    public static String getSysVersion() {
        return "VOD 1.0";
    }

    /**
     * Returns the global Locale used by Jive. A locale specifies language
     * and country codes, and is used for internationalization. The default
     * locale is Locale.US
     *
     * @return the global locale used by Jive.
     */
    public static Locale getLocale() {
        if (locale == null) {
            loadLocale();
        }
        return locale;
    }

    /**
     * Sets the global locale used by Jive. A locale specifies language
     * and country codes, and is used for internationalization. The default
     * locale is Locale.US
     *
     * @param locale the global Locale for Jive.
     */
    public static void setLocale(Locale newLocale) {
        locale = newLocale;
        // Save values to Jive properties.
        setSysProperty("locale.country", locale.getCountry());
        setSysProperty("locale.language", locale.getLanguage());
        // Reset the date formatter objects
        dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, locale);
        dateTimeFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,
                DateFormat.MEDIUM, locale);
        dateFormat.setTimeZone(timeZone);
        dateTimeFormat.setTimeZone(timeZone);
    }

    /**
     * Returns a Vod property.
     *
     * @param name the name of the property to return.
     * @return the property value specified by name.
     */
    public static String getSysProperty(String name) {
        loadProperties();
        return properties.getProperty(name);
    }

    /**
     * Sets a Vod property. If the property doesn't already exists, a new
     * one will be created.
     *
     * @param name the name of the property being set.
     * @param value the value of the property being set.
     */
    public static void setSysProperty(String name, String value) {
        loadProperties();
        properties.setProperty(name, value);
    }

    /**
     * Deletes a Jive property. If the property doesn't exist, the method
     * does nothing.
     *
     * @param name the name of the property to delete.
     */
    public static void deleteSysProperty(String name) {
        loadProperties();
        properties.deleteProperty(name);
    }

    /**
     * Loads properties if necessary. Property loading must be done lazily so
     * that we give outside classes a chance to set <tt>jiveHome</tt>.
     */
    private synchronized static void loadProperties() {
            // If jiveHome is still null, no outside process has set it and
            // we have to attempt to load the value from jive_init.properties,
            // which must be in the classpath.
            if (vodHome == null) {
                vodHome = new InitPropLoader().getVodHome();
            }
            //Create a manager with the full path to the xml config file.
            properties = new XMLProperties(vodHome + File.separator +
                    VOD_CONFIG_FILENAME);

    }
    /**
     * Load locale and timezone information.
     */
    private synchronized static void loadLocale() {
        String language = getSysProperty("locale.language");
        if (language == null) {
            language = "";
        }
        String country = getSysProperty("locale.country");
        if (country == null) {
            country = "";
        }
        // If no locale info is specified, default to Locale.US
        if (language.equals("") && country.equals("")) {
            locale = Locale.US;
        }
        else {
            locale = new Locale(language, country);
        }
        String timeZoneID = getSysProperty("locale.timeZone");
        if (timeZoneID == null) {
            timeZone = TimeZone.getDefault();
        }
        else {
            timeZone = TimeZone.getTimeZone(timeZoneID);
        }
        dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, locale);
        dateTimeFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,
                DateFormat.MEDIUM, locale);
        dateFormat.setTimeZone(timeZone);
        dateTimeFormat.setTimeZone(timeZone);
    }
    /**
     * Formats a Date object to return a date and time using the global locale.
     */
    public static String formatDateTime(Date date) {
        if (dateTimeFormat == null) {
            loadLocale();
        }
        return dateTimeFormat.format(date);
    }
    
    public static String TransferBiaoZhuangTai(String zhuangTai)
    {
    	if(zhuangTai.equals(SH_STATE_DD))
    	{
    		zhuangTai = "等待审核";
    	}
    	else if(zhuangTai.equals(SH_STATE_JJ))
    	{
    		zhuangTai= "审核拒绝";
    	}
    	else if(zhuangTai.equals(SH_STATE_TJ)) 
    	{
    		zhuangTai = "审核通过";	
    	}
    	
    	return zhuangTai;
    }

}
